package com.ruoyi.business.controller;

import com.ruoyi.business.domain.bo.HomeWorkStuBo;
import com.ruoyi.business.domain.bo.NoticeBo;
import com.ruoyi.business.domain.vo.HomeWorkStuVo;
import com.ruoyi.business.domain.vo.NoticeVo;
import com.ruoyi.business.service.INoticeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.ApiOperation;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 最爱喝兽奶
 * @create 2022/9/21
 **/
@RestController
@RequestMapping("/business/notice")
public class NoticeController extends BaseController {

    @Autowired
    private INoticeService noticeService;

    @ApiOperation("获取作业信息的列表")
    @GetMapping("/list")
    public AjaxResult list(NoticeBo bo) {
        TableDataInfo<NoticeVo> result = noticeService.queryNoticeByPage(bo);
        return AjaxResult.success(result);
    }

    @ApiOperation("根据传入id删除公告")
    @DeleteMapping("/{id}")
    public AjaxResult deleteNoticeById(@PathVariable("id") String id) {
        if ("undefined".equals(id)) {
            return AjaxResult.error();
        }
        noticeService.deleteById(id);
        return AjaxResult.success();
    }

    @ApiOperation("修改公告信息")
    @PutMapping
    public AjaxResult updateNotice(@RequestBody NoticeBo bo) {
        noticeService.updateNoticeById(bo);
        return AjaxResult.success();
    }

    @ApiOperation("新增公告信息")
    @PostMapping
    public AjaxResult addNotice(@RequestBody NoticeBo bo) {
        noticeService.addNotice(bo);
        return AjaxResult.success();
    }

    @ApiOperation("查询一条告示信息")
    @GetMapping("/{id}")
    public AjaxResult getNoticeById(@PathVariable("id") String id) {
        NoticeVo vo = noticeService.getNoticeById(id);
        return AjaxResult.success(vo);
    }

    @ApiOperation("公告上移")
    @GetMapping("/move/up/{id}")
    public AjaxResult moveUp(@PathVariable("id") String id) {
        noticeService.moveUp(id);
        return AjaxResult.success();
    }

    @ApiOperation("公告下移")
    @GetMapping("/move/down/{id}")
    public AjaxResult moveDown(@PathVariable("id") String id) {
        noticeService.moveDown(id);
        return AjaxResult.success();
    }



}
